home *** CD-ROM | disk | FTP | other *** search
/ com!online 2005 May / com_0505_1.iso / opensource / top10 / amc_install.exe / {app} / Scripts / IMP Awards.ifs < prev    next >
Encoding:
Text File  |  2004-09-03  |  4.2 KB  |  148 lines

  1. // GETINFO SCRIPTING
  2. // IMP Awards v1.0 by micmic.ifs
  3.  
  4. (***************************************************
  5.  *  Movie importation script for:                  *
  6.  *      IMP Awards http://www.impawards.com/       *
  7.  *                                                 *
  8.  *  (c) micmic                                     *
  9.  *                                                 *
  10.  *  For use with Ant Movie Catalog 3.4.2           *
  11.  *  www.antp.be/software/moviecatalog              *
  12.  *                                                 *
  13.  *  This program is free software; you can         *
  14.  *  redistribute it and/or modify it under the     *
  15.  *  terms of the GNU General Public License as     *
  16.  *  published by the Free Software Foundation;     *
  17.  *  either version 2 of the License, or (at your   *
  18.  *  option) any later version.                     *
  19.  ***************************************************)
  20.  
  21. program micmic;
  22. var
  23.   MovieName: string;
  24. const
  25.   BaseURL = 'http://www.impawards.com/cgi-bin/htsearch?method=or&words=';
  26.  
  27. function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer;
  28. var
  29.   i: Integer;
  30. begin
  31.   result := -1;
  32.   if StartAt < 0 then
  33.     StartAt := 0;
  34.   for i := StartAt to List.Count-1 do
  35.     if Pos(Pattern, List.GetString(i)) <> 0 then
  36.     begin
  37.       result := i;
  38.       Break;
  39.     end;
  40. end;
  41.  
  42. procedure AnalyzePage(Address: string);
  43. var
  44.   Page: TStringList;
  45.   LineNr: Integer;
  46.   PosIni, PosFin: Integer;
  47.   Line, SubLine: string;
  48.   Title, DirURL: string;
  49.   txtTemp: string;
  50. begin
  51.   Page := TStringList.Create;
  52.   Page.Text := GetPage(Address);
  53.   if Pos('IMP could not find any matches for', Page.Text) > 0 then
  54.   begin
  55.     ShowMessage('No matches for the title search.');
  56.   end else
  57.   begin
  58.     PickTreeClear;
  59.     PickTreeAdd('Resuts for the search of "' + MovieName + '":', '');
  60.  
  61.     // buscamos los resultados
  62.     LineNr := 0;
  63.  
  64.     while LineNr < Page.Count do
  65.     begin
  66.       SubLine := Page.GetString(LineNr);
  67.       txtTemp := '<dl><dt><strong><a href="';
  68.       PosIni := pos(txtTemp, SubLine);
  69.       if PosIni > 0 then
  70.       begin
  71.         //ShowMessage(IntToStr(PosIni));
  72.         SubLine := Copy(SubLine, PosIni + Length(txtTemp), Length(SubLine));
  73.        
  74.         txtTemp := '">';
  75.         PosFin := pos(txtTemp, SubLine);
  76.         DirURL := Copy(SubLine, 1, PosFin - 1);
  77.        
  78.         SubLine := Copy(SubLine, PosFin + Length(txtTemp), Length(SubLine));
  79.         txtTemp := '</a>';
  80.         PosFin := pos(txtTemp, SubLine);
  81.         Title := Copy(SubLine, 1, PosFin - 1);
  82.  
  83.         //ShowMessage(Title + '-->' + DirURL);
  84.         PickTreeAdd(Title, DirURL);
  85.       end;
  86.       LineNr := LineNr + 1;
  87.     end;
  88.  
  89.     Page.Free;
  90.     if PickTreeExec(Address) then
  91.       AnalyzeMoviePage(Address);
  92.   end;
  93. end;
  94.  
  95.  
  96. procedure AnalyzeMoviePage(Address: string);
  97. var
  98.   Page: TStringList;
  99.   PosIni, PosFin: Integer;
  100.   dirBase: string;
  101.   txtTemp: string;
  102.   ImgTMP: string;
  103. begin
  104.   Page := TStringList.Create;
  105.   Page.Text := StringReplace(GetPage(Address), '<br>', #13#10);
  106.  
  107.   //obtenemos directorio base
  108.   PosFin := 0;
  109.   dirBase := Address;
  110.   PosIni := pos('/', dirBase);
  111.   while PosIni > 0 do
  112.   begin
  113.     PosFin := PosFin + PosIni;
  114.     dirBase := Copy(dirBase, PosIni + 1, Length(DirBase));
  115.     PosIni := pos('/', dirBase);
  116.   end;
  117.   dirBase := Copy(Address, 1, PosFin);
  118.  
  119.   //buscamos la imagen
  120.   txtTemp := '<img SRC="posters/';
  121.   PosIni := pos(txtTemp, Page.Text);
  122.   if PosIni > 0 then
  123.   begin
  124.     txtTemp := Copy(Page.Text, PosIni + Length(txtTemp), 100);
  125.     PosFin := pos('"', txtTemp);
  126.     ImgTMP := Copy(txtTemp, 1, PosFin - 1);
  127.  
  128.     GetPicture(dirBase + 'posters/' + ImgTMP, False);
  129.   end;
  130.  
  131.   Page.Free;
  132.   DisplayResults;
  133. end;
  134.  
  135. // bmicmic: Bucle Principal
  136. begin
  137.   if CheckVersion(3,4,0) then
  138.   begin
  139.     MovieName := GetField(fieldOriginalTitle);
  140.     if MovieName = '' then
  141.       MovieName := GetField(fieldTranslatedTitle);
  142.     Input('Import of IMP Awards', 'Enter the title of the movie:', MovieName);
  143.     AnalyzePage(BaseURL + UrlEncode(MovieName));
  144.  
  145.   end else
  146.        ShowMessage('This scripts requires a new version of Ant Movie Catalog (at least the version 3.4.2)');
  147. end.
  148.